$(document).ready(function(){
  $("form#uploadForm").submit(function() { // uploadForm is submitted
	
	var photo = $('#photo').attr('value'); // get photo
	//var photo = $("input#photo").val();
	var photoUrl = 'http://www.sven-s.com/wp-content/uploads/2011/06/demo11.jpg'; 
	alert(photo);
	if (photo && photoUrl) { // values are not empty
	      $.ajax({
	        type: "GET",
	        url: "cgi-bin/upload.cgi", // URL of the Perl script
	        contentType: "application/json; charset=utf-8",
	        dataType: "json",
	        // send photo and photoUrl as parameters to the Perl script
	        data: "photo=" + photo + "&photoUrl=" + photoUrl,
	        // script call was *not* successful
	        error: function(XMLHttpRequest, textStatus, errorThrown) { 
	          $('div#loginResult').text("responseText: " + XMLHttpRequest.responseText 
	            + ", textStatus: " + textStatus 
	            + ", errorThrown: " + errorThrown);
	          $('div#loginResult').addClass("error");
	        }, // error 
	        // script call was successful 
	        // data contains the JSON values returned by the Perl script 
	        success: function(data){
	          if (data.error) { // script returned error
	            $('div#loginResult').text("data.error: " + data.error);
	            $('div#loginResult').addClass("error");
	          } // if
	          else { // login was successful
	            //$('form#loginForm').hide();
	            $('div#loginResult').text("data.success: " + data.success 
	              + ", data.userid: " + data.userid);
	            $("#imgResult").attr("src", "upload/h5.jpg");
	           // alert("upload/" + data.success); 
	            $('div#loginResult').addClass("success");
	          } //else
	        } // success
	      }); // ajax
	    } // if
	    else {
	      $('div#loginResult').text("enter photo and photoUrl");
	      $('div#loginResult').addClass("error");
	    } // else
	    $('div#loginResult').fadeIn();
	    return false;
  });
});